/*
 * RuleBaseManager.java
 *
 * Created on 2006-4-28
 * Original Author: Schweigen
 *
 * Changes
 * ---------
 * $Log: RuleBaseManager.java,v $
 * Revision 1.2  2010/01/13 06:42:49  cvs
 * *** empty log message ***
 *
 * Revision 1.1  2009/06/22 11:51:49  cvs
 * *** empty log message ***
 *
 * Revision 1.1  2009/05/05 09:00:33  cvs
 * *** empty log message ***
 *
 *
 */

package com.et114.components.rule;

import org.apache.commons.lang.StringUtils;
import org.drools.RuleBase;
import org.drools.WorkingMemory;

/**

 */
public class RuleBaseManager {
	private RuleBaseLoader	ruleBaseLoader;
	private RuleBase		ruleBase;
	
	public void setRuleBaseLoader ( RuleBaseLoader ruleBaseLoader ) {
		this.ruleBaseLoader = ruleBaseLoader;
	}
	
	/**
	 * @see RuleBaseManager#getSession(String)
	 */
	public WorkingMemory getSession ( String ruleGroup ) throws Exception {
		if ( ruleBase == null ) {
			ruleBase = ruleBaseLoader.buildRuleBase ( );
		}
		
		WorkingMemory wm = ruleBase.newWorkingMemory ( );
		if ( StringUtils.isNotEmpty ( ruleGroup ) ) {
			wm.setFocus ( ruleGroup );
		}
		
		return wm;
	}
	
	/**
	 * @see RuleBaseManager#getSession(String)
	 */
	public WorkingMemory getSession ( ) throws Exception {
		return getSession ( null );
	}
	
}
